﻿using System.Linq;
using System.Reflection;

namespace Castle.MonoRail.ExtensionMethods.Helpers {
	public static class CustomAttributeExtensions {
		public static T[] GetCustomAttributes<T>(this MemberInfo m) {
			return m.GetCustomAttributes(typeof (T), true).Cast<T>().ToArray();
		}

		public static bool HasCustomAttribute<T>(this MemberInfo m) {
			return m.GetCustomAttributes<T>().Length > 0;
		}

		public static T[] GetCustomAttributes<T>(this ParameterInfo m) {
			return m.GetCustomAttributes(typeof(T), true).Cast<T>().ToArray();			
		}

		public static bool HasCustomAttribute<T>(this ParameterInfo m) {
			return m.GetCustomAttributes<T>().Length > 0;			
		}
	}
}